<?php


namespace app\lunwen\controller;


use app\lunwen\model\StudentModel;
use cmf\controller\HomeBaseController;
use think\Session;

class LoginController extends HomeBaseController
{
    public function index(){
        $this->assign("msg","1");
        /*Session::set('username',$_POST["name"]);*/
        return $this->fetch(':login');
    }

    public function loginOut(){
        session(null);
        $this->assign("msg","1");
        return $this->fetch(':login');
    }

    public function login_check(){

        //null
        $year = $_POST["yearConfig"];
        $beforeYear = substr($year,0,7);
        $afterYear = substr($year,10,16);

        //学生登入检测
        $param = $this->request->param();
        $student = new StudentModel();
        $data = $student->where("user_id", $_POST["userId"])
            ->where("stu_name", $_POST["name"])
            ->where("stu_id", $param['studentId'])->find();
        if ($data == null) {
            return json([
                'code'=>-1,
                'msg'=>'账号或姓名或身份证错误',
            ]);
        } else {
            session('stu_name', $data->stu_name);
            session('stu_id', $_POST["studentId"]);
            session("year", $_POST["yearConfig"]);
            session("beforeYear", $beforeYear);
            session("afterYear", $afterYear);
            return json([
                'msg'=>'登录成功',
                'code'=>1,
            ]);
        }
    }
}